/**
 * 
 */
package com.pxingg.datetime;

import junit.framework.Assert;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author pxingg
 * 
 */
public class TimerTest
{
    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception
    {
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#getEnd()}.
     */
    @Test
    public final void testGetEnd()
    {
        final Timer timer = new Timer();

        Assert.assertEquals(timer.getEnd(), Timer.INVALID_TIME_STAMP);

        final Timer timer2 = new Timer("timer");

        Assert.assertEquals(timer2.getEnd(), Timer.INVALID_TIME_STAMP);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#getInterval()}.
     */
    @Test
    public final void testGetInterval()
    {
        final Timer timer = new Timer();
        timer.start();
        timer.stop();
        Assert.assertTrue(timer.getInterval() >= 0);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#getName()}.
     */
    @Test
    public final void testGetName()
    {
        final Timer timer = new Timer("timer");
        Assert.assertEquals(timer.getName(), "timer");
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#getStart()}.
     */
    @Test
    public final void testGetStart()
    {
        final Timer timer = new Timer();

        Assert.assertEquals(timer.getStart(), Timer.INVALID_TIME_STAMP);

        final Timer timer2 = new Timer("timer");

        Assert.assertEquals(timer2.getStart(), Timer.INVALID_TIME_STAMP);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#isStarted()}.
     */
    @Test
    public final void testIsStarted()
    {
        final Timer timer = new Timer();
        Assert.assertFalse(timer.isStarted());
        timer.start();
        Assert.assertTrue(timer.isStarted());
        timer.stop();
        Assert.assertFalse(timer.isStarted());

        timer.restart();
        Assert.assertTrue(timer.isStarted());
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#isStoped()}.
     */
    @Test
    public final void testIsStoped()
    {
        final Timer timer = new Timer();
        timer.start();
        Assert.assertFalse(timer.isStoped());
        timer.stop();
        Assert.assertTrue(timer.isStoped());

        // run start again, program can workS
        timer.start();
        Assert.assertFalse(timer.isStoped());
        timer.stop();
        Assert.assertTrue(timer.isStoped());

        timer.restart();
        Assert.assertFalse(timer.isStoped());
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#restart()}.
     */
    @Test
    public final void testRestart()
    {
        final Timer timer = new Timer();
        timer.start();
        final long timeStart1 = timer.getStart();
        timer.restart();
        final long timeStart2 = timer.getStart();
        Assert.assertTrue(timeStart2 >= timeStart1);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#setEnd(long)}.
     */
    @Test
    public final void testSetEnd()
    {
        final Timer timer = new Timer();
        timer.setEnd(100000);

        Assert.assertEquals(timer.getEnd(), 100000);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#setName(java.lang.String)}.
     */
    @Test
    public final void testSetName()
    {
        final Timer timer = new Timer();
        timer.setName("timer");
        Assert.assertEquals(timer.getName(), "timer");
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#setStart(long)}.
     */
    @Test
    public final void testSetStart()
    {
        final Timer timer = new Timer();
        timer.setStart(100000);

        Assert.assertEquals(timer.getStart(), 100000);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#start()}.
     */
    @Test
    public final void testStart()
    {
        final Timer timer = new Timer();
        timer.setStart(1000);
        Assert.assertEquals(timer.getStart(), 1000);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#stop()}.
     */
    @Test
    public final void testStop()
    {
        final Timer timer = new Timer();
        timer.start();
        timer.stop();
        Assert.assertTrue(timer.getEnd() >= timer.start);
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#Timer()}.
     */
    @Test
    public final void testTimer()
    {
        final Timer timer = new Timer();

        Assert.assertEquals(timer.getStart(), Timer.INVALID_TIME_STAMP);
        Assert.assertEquals(timer.getEnd(), Timer.INVALID_TIME_STAMP);
        Assert.assertEquals(timer.toString(), "Timer[dummy] is not start yet");
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#Timer(java.lang.String)} .
     */
    @Test
    public final void testTimerString()
    {
        final Timer timer = new Timer("a Timer");

        Assert.assertEquals(timer.getStart(), Timer.INVALID_TIME_STAMP);
        Assert.assertEquals(timer.getEnd(), Timer.INVALID_TIME_STAMP);
        Assert.assertEquals(timer.toString(), "Timer[a Timer] is not start yet");
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#toString()}.
     */
    @Test
    public final void testToString()
    {
        final Timer timer = new Timer();
        Assert.assertEquals(timer.toString(), "Timer[dummy] is not start yet");

        timer.setName("a Timer");

        Assert.assertEquals(timer.toString(), "Timer[a Timer] is not start yet");
    }

    /**
     * Test method for {@link com.pxingg.datetime.Timer#getTimebyMillisecond(long)}.
     */
    @Test
    public final void timer()
    {
        final Timer timer = new Timer();
        Assert.assertEquals(timer.getTimebyMillisecond(1291914428656L), "2010-12-10 01:07:08.656");
    }
}
